/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;

/**
 * <p>Project: jse2204 - LocalDate1
 * <p>Powered by webrx On 2022-08-31 11:26:55
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class LocalDate1 {
    public static void main(String[] args) {
        //java.util.Date Calendar  java.text.SimpleDateFormat  java.time.LocalDate
        //java.util.Date()

        //java 1.8 新日期API 只保留年月日
        LocalDate now = LocalDate.now();
        //1 星期日 2 星期一 7 星期六
        now = LocalDate.of(2020,8,28);
        System.out.println(now);

        //格式化 java.time.format.DateTimeFormatter 格式化类
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy年MM月dd日 e");
        System.out.println(now.format(df));

        //isLeapYear() 判断是不是闰年
        System.out.println(now.isLeapYear());

        LocalDate n = LocalDate.now();
        System.out.println(n);

        //mybatis plus
        System.out.println(n.plusDays(14));
        System.out.println(n.plusWeeks(2));
        System.out.println(n.minusYears(5));
        System.out.println(n.plusYears(-5));

        //java.util.Date 日期 + 时间
        LocalDateTime nn = LocalDateTime.now();
        DateTimeFormatter ddd = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss E");
        System.out.println(nn.format(ddd));
        System.out.println(nn.plus(1000, ChronoUnit.MINUTES).format(ddd));

        LocalDate dd1 = nn.toLocalDate();
        LocalTime tt1 = nn.toLocalTime();

        LocalTime tt = LocalTime.now();
        System.out.println(tt);

    }
}
